package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.VariousKindsVideoVo;
import com.ruoyi.system.domain.bo.VariousKindsVideoBo;
import com.ruoyi.system.service.IVariousKindsVideoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 视频Controller
 *
 * @author ruoyi
 * @date 2022-03-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/kindsVideo")
public class VariousKindsVideoController extends BaseController {

    private final IVariousKindsVideoService iVariousKindsVideoService;

    /**
     * 查询视频列表
     */
    @SaCheckPermission("system:kindsVideo:list")
    @GetMapping("/list")
    public TableDataInfo<VariousKindsVideoVo> list(@Validated(QueryGroup.class) VariousKindsVideoBo bo, PageQuery pageQuery) {
        return iVariousKindsVideoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出视频列表
     */
    @SaCheckPermission("system:kindsVideo:export")
    @Log(title = "视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated VariousKindsVideoBo bo, HttpServletResponse response) {
        List<VariousKindsVideoVo> list = iVariousKindsVideoService.queryList(bo);
        ExcelUtil.exportExcel(list, "视频", VariousKindsVideoVo.class, response);
    }

    /**
     * 获取视频详细信息
     */
    @SaCheckPermission("system:kindsVideo:query")
    @GetMapping("/{id}")
    public R<VariousKindsVideoVo> getInfo(
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iVariousKindsVideoService.queryById(id));
    }

    /**
     * 新增视频
     */
    @SaCheckPermission("system:kindsVideo:add")
    @Log(title = "视频", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VariousKindsVideoBo bo) {
        return toAjax(iVariousKindsVideoService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改视频
     */
    @SaCheckPermission("system:kindsVideo:edit")
    @Log(title = "视频", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VariousKindsVideoBo bo) {
        return toAjax(iVariousKindsVideoService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除视频
     */
    @SaCheckPermission("system:kindsVideo:remove")
    @Log(title = "视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iVariousKindsVideoService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
